home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / SAT 2.3b4 / Demo ƒ / StepZkrolly demo ƒ / StepZkrolly.c next >
Text File  |  1995-01-17  |  3KB  |  116 lines

  1.  
  2. //• C translation from Pascal source file: Zkrolly.p
  3.  
  4. //• main Zkrolly;
  5. #include "SAT.h"
  6.  
  7. extern void        InitXprite(void);
  8. extern pascal void        SetupXprite(SpritePtr me);
  9. extern pascal void        HandleXprite(SpritePtr me);
  10. extern void        InitZprite(void);
  11. extern pascal void        SetupZprite(SpritePtr me);
  12. extern pascal void        HandleZprite(SpritePtr me);
  13.  
  14.  
  15. SpritePtr ignoresp, zp;
  16. WindowPtr Zwind;
  17. Rect r;
  18.  
  19. enum {
  20.     scrollSizeH = 250,
  21.     scrollSizeV = 200
  22. };
  23.  
  24. Point nowOff = {0,0};
  25.  
  26. #define max(x, y)    (x>y?x:y)
  27. #define min(x, y)    (x>y?y:x)
  28. #define abs(x)        ((x)>0?(x):-(x))
  29.  
  30. pascal Boolean Zteppy()
  31. {
  32.     Rect srcRect;
  33.     Point    where;
  34.     
  35.     where = zp->position;
  36.     where.h -= (scrollSizeH >> 1);
  37.     where.v -= (scrollSizeV >> 1);
  38.     if (where.h < 0)
  39.         where.h = 0;
  40.     if (where.v < 0)
  41.         where.v = 0;
  42.     if (where.h + scrollSizeH > gSAT.offSizeH)
  43.         where.h = gSAT.offSizeH - scrollSizeH;
  44.     if (where.v + scrollSizeV > gSAT.offSizeV)
  45.         where.v = gSAT.offSizeV - scrollSizeV;
  46.  
  47.     if ((abs(where.h - nowOff.h) > scrollSizeH / 3) || (abs(where.v - nowOff.v) > scrollSizeV / 3))
  48.         do
  49.             {
  50.                 if (nowOff.h > where.h) 
  51.                     nowOff.h = max(nowOff.h - 5, where.h);
  52.                 if (nowOff.h < where.h) 
  53.                     nowOff.h = min(nowOff.h + 5, where.h);
  54.                 if (nowOff.v > where.v) 
  55.                     nowOff.v = max(nowOff.v - 5, where.v);
  56.                 if (nowOff.v < where.v) 
  57.                     nowOff.v = min(nowOff.v + 5, where.v);
  58.                 SATSetPortScreen();
  59.                 SetOrigin(nowOff.h, nowOff.v);
  60.  
  61.                 srcRect = gSAT.wind.port->portRect;
  62.  
  63.                 CopyBits(&gSAT.offScreen.port->portBits, &gSAT.wind.port->portBits, &srcRect, &srcRect, srcCopy, nil);
  64.             }
  65.         while ((nowOff.h != where.h) || (nowOff.v != where.v));
  66. }
  67.  
  68. void SetupZwind()
  69. {
  70.     Rect zr;
  71.     SysEnvRec wrld;
  72.     
  73.     //• Since SAT hasn't been initialized, we can't use gSAT.colorFlag but 
  74.     //• have to check environs ourselves.
  75.     if ( noErr != SysEnvirons(1, &wrld))
  76.         ;//• ignore errors.
  77.     SetRect(&zr, 20, 30, 20 + scrollSizeH, 30 + scrollSizeV);
  78.     if ( wrld.hasColorQD )
  79.         Zwind = NewCWindow(0L, &zr, "\p", false, plainDBox, (WindowPtr)-1L, false, 0);
  80.     else
  81.         Zwind = NewWindow(0L, &zr, "\p", false, plainDBox, (WindowPtr)-1L, false, 0);
  82. }
  83.  
  84.  
  85. main ()
  86. {
  87.     SATInitToolbox();
  88.  
  89.     SetupZwind ();
  90.  
  91.     SetRect(&r, 0, 0, 510, 340);
  92.     SATCustomInit(128, 129, &r, Zwind, 0L, false, false, false, true, false);
  93.     InitXprite ();
  94.     InitZprite ();
  95.     ShowWindow(gSAT.wind.port);
  96.     SelectWindow(gSAT.wind.port);
  97.     zp = SATNewSprite(0, 90, 70, &SetupZprite);
  98.     ignoresp = SATNewSprite(0, 120, 100, &SetupXprite);
  99.     ignoresp = SATNewSprite(0, 200, 160, &SetupXprite);
  100.     SATSoundOff();
  101.     SATRedraw();
  102.     SATSetPortScreen();
  103.     do
  104.     {
  105.         SATRun(true);
  106.         Zteppy();
  107.     } while (! Button ());
  108.  
  109.     //• WARNING! It seems like we mess up the current device somewhere. 
  110.     //• Probably a bug in SAT (where the device setting isn't perfect 
  111.     //• yet). Let's set port and device to something nice and safe!.
  112.     SATSetPortScreen();
  113. /* Finally, make sure we dispose of the sound channel. */
  114.     SATSoundShutup();
  115. }
  116.